package com.shike.web.controller;

import com.shike.core.storage.AbstractStorage;
import com.shike.core.storage.StorageService;
import com.shike.core.utils.R;
import com.shike.web.service.ZqFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UploadController {

    @Autowired
    private StorageService storageService;

    @Autowired
    private ZqFileService zqFileService;


    /**
     * 文件上传方法
     * @param mfile
     * @return 文件地址
     * @throws Exception
     */
    @RequestMapping(value = "/upload")
    public R handleFileUpload(@RequestParam("file") MultipartFile mfile) throws Exception {
        if (mfile != null) {
            System.out.println(mfile.getOriginalFilename());
            System.out.println(mfile.getName());
            String url = storageService.storage(mfile.getInputStream(), AbstractStorage.MIME_TYPE_IMAGE, mfile.getOriginalFilename());
            return R.successObj(url);
        }else{
            return R.PARAME_ERROR;
        }
    }
}
